package sample.chapter7.navigating;

import java.util.NavigableSet;
import java.util.TreeSet;

/**
 * A sample class demonstrating efficiency of <node>NavigableSet</node>
 * in Java 6 over Java 5. 
 * <p>
 * lower/floor<br>
 * higher/ceiling
 * 
 * @author kan.sun
 *
 */
public class Ferry
{
	public static void main(String[] args)
	{
		NavigableSet<Integer> times = new TreeSet<Integer>();
		times.add(1205);
		times.add(1505);
		times.add(1545);
		times.add(1600);
		times.add(1830);
		times.add(2000);
		times.add(2010);
		times.add(2100);
		
		//Java 5 version
		TreeSet<Integer> subset = new TreeSet<Integer>();
		subset = (TreeSet<Integer>)times.headSet(1600, true);
		System.out.println("J5 - last before 4pm is: "+subset.last());
		
		TreeSet<Integer> sub2 = new TreeSet<Integer>();
		sub2 = (TreeSet<Integer>)times.tailSet(2000);
		System.out.println("J5 - first after 8pm is: "+sub2.first());
		
		//Java 6 version
		System.out.println("J6 - last before 4pm is: "+times.lower(1600));
		System.out.println("J6 - first after 8pm is: "+times.ceiling(2000));
	}
}
